#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=14;
long long dp[1<<13][maxn][maxn],ways[1<<13][maxn][maxn];
int v[maxn],g[maxn][maxn];
int n,m,t;
int count(int x)
{
	x=(x & 0x55555555) + ((x >> 1) & 0x55555555); 
	x=(x & 0x33333333) + ((x >> 2) & 0x33333333); 
	x=(x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F); 
	x=(x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF); 
	x=(x & 0x0000FFFF) + ((x >> 16) & 0x0000FFFF);
	return x;
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		memset(g,0,sizeof(g));
		memset(dp,0,sizeof(dp));
		memset(ways,0,sizeof(ways));
		scanf("%d%d",&n,&m);
		for(int i =1;i<=n;i++)
			scanf("%d",&v[i]);
		for(int i=1;i<=m;i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			g[x][y]=g[y][x]=1;
		}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(i!=j&&g[i][j])
				{
					dp[(1<<(j-1))+(1<<(i-1))][i][j]=v[i]+v[j]+v[i]*v[j];
					ways[(1<<(j-1))+(1<<(i-1))][i][j]=1;
				}
		for(int s=3;s< (1<<n);s++)
		{
			int x=count(s);
			if(x<=2)continue;
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					if(g[i][j]&& i!=j && (1<<(i-1)&s) && (1<<(j-1)&s) )
					{
						for(int k=1;k<=n;k++)
						if(k!=i&&k!=j&&(1<<(k-1)&s)&&g[k][i])
						{
							int ss=s-(1<<(j-1));
							int tem=dp[ss][k][i];
							if(tem==0)continue;
							tem=tem+v[j]+v[i]*v[j];
							if(g[k][j])tem+=v[i]*v[j]*v[k];
							if(tem==dp[s][i][j])
								ways[s][i][j]+=ways[ss][k][i];
							if(tem>dp[s][i][j])
							{
								dp[s][i][j]=tem;
								ways[s][i][j]=ways[ss][k][i];
							}
						}
					}
		}
		long long max=-1,ans=0;
		int state=(1<<n)-1;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
			{
				//printf("dp[%d][%d]=%lld\n",i,j,dp[state][i][j]);
				if(dp[state][i][j]==max)
					ans+=ways[state][i][j];

				if(dp[state][i][j]>max)
				{
					max=dp[state][i][j];
					ans=ways[state][i][j];
				}
							}
		if(n==1)cout<<v[1]<<" 1"<<endl;
		else cout<<max<<" "<<ans/2<<endl;
	}
	return 0;
}

				
				


			



